# -*- coding: utf-8 -*-
"""
@Time: 2021/12/10 10:35
@Author: jins
@File: table_uelectricoutts.py
@Introduction: uelectricoutts表造数据
"""

from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        data_time = datetime(2021, 11, 1, 0, 0, 0)
        ElectricityApT = 1000.00  # 正向有功总电量原始值(千瓦时)
        ElectricityRpT = 500.00  # 正向无功总电量原始值(千乏时)
        for i in range(2880):
            unit_id = 10000000 + j
            PowerApT = random.uniform(3000.0, 5000.0)  # 总有功功率原始值(千瓦)
            PowerRpT = random.uniform(500.0, 1000.0)  # 总无功功率原始值(千乏)
            increase_num = random.uniform(5.0, 10.0)
            UpdateTime = data_time.timestamp()*1000
            sql = f"""INSERT INTO xlcloud.uelectricoutts21b
            VALUES
                (   
                    {unit_id},
                    {unit_id},
                    '{data_time}',
                    {ElectricityApT},
                    {ElectricityRpT},
                    {PowerApT},
                    {PowerRpT},
                    1,
                    1,
                    {UpdateTime})
                    """
            op.batch_excute(sql)
            data_time += timedelta(minutes=15)
            ElectricityApT += increase_num
            ElectricityRpT += increase_num
        op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)
